<?php
/* @var $this CardInfoController */
/* @var $model CardInfo */
/* @var $form CActiveForm */
$defaultpay = CardInfo::model()->checkboxValid();
if(empty($defaultpay)){
    $defaultpay=0;
}
Yii::app()->clientScript->registerScript('admin', "
$(document).ready(function(){
        if($defaultpay == 1){
             $('#bank_card').hide();
        }else if($defaultpay == 0){
             $('#bank_card').hide();
        }else{
              $('#vista').hide();
        }
	$('#CardInfo_card_type').change(function(){
		var isreback = $(this).val();
			if(isreback==1){
                            $('#bank_card').hide();
                            $('#vista').show();
			}else if(isreback=2){
                            $('#bank_card').show();
                            $('#vista').hide();
			}
		})
	})
")
?>
<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'card-info-form',
	'enableAjaxValidation'=>false,
)); ?>

	<p class="note"><?php echo Yii::t('base','Fields with <span class="required">*</span> are required.');?></p>

	<?php echo $form->errorSummary($model); ?>
       
        <div class="row">
		<?php echo $form->labelEx($model,'card_type'); ?>
        <?php echo $form->dropDownList($model,'card_type',array('1'=>Yii::t('base','Credit Card')/*,'2'=>Yii::t('base','Direct Debit')*/)) ?>
        <?php //echo $form->textField($model,'card_type',array('size'=>50,'maxlength'=>50,'value'=>Yii::t('base','Credit Card'),'readonly'=>true)); ?>
		<?php echo $form->error($model,'card_type'); ?>
	</div>
<div id="vista">
	<div class="row" >
		<?php echo $form->labelEx($model,'card_number'); ?>
		<?php echo $form->textField($model,'card_number',array('size'=>50,'maxlength'=>50)); ?>
		<?php echo $form->error($model,'card_number'); ?>
	</div>

	<div class="row" >
		<?php echo $form->labelEx($model,'name'); ?>
		<?php echo $form->textField($model,'name',array('size'=>50,'maxlength'=>50)); ?>
		<?php echo $form->error($model,'name'); ?>
	</div>
       
	<div class="row" >
		<?php echo $form->labelEx($model,'expirydate'); ?>
		<?php echo $form->textField($model,'expirydate',array('size'=>50,'maxlength'=>50)); ?>
		<?php echo $form->error($model,'expirydate'); ?>
	</div>
         <div class="row" id="two">
                <?php echo  Yii::t('base','Save for Future Recharge'); ?>
                <?php echo $form->checkBox($model,'defaultpay',array('value'=>1)); ?>
        </div>
</div>

<div id="bank_card">
	<div class="row" >
		<?php echo $form->labelEx($model,'card_accountname'); ?>
		<?php echo $form->textField($model,'card_accountname',array('size'=>60,'maxlength'=>100)); ?>
		<?php echo $form->error($model,'card_accountname'); ?>
	</div>

	<div class="row" >
		<?php echo $form->labelEx($model,'card_bsbnumber'); ?>
		<?php echo $form->textField($model,'card_bsbnumber',array('size'=>50,'maxlength'=>50)); ?>
		<?php echo $form->error($model,'card_bsbnumber'); ?>
	</div>

	<div class="row" >
		<?php echo $form->labelEx($model,'card_accountnumber'); ?>
		<?php echo $form->textField($model,'card_accountnumber',array('size'=>50,'maxlength'=>50)); ?>
		<?php echo $form->error($model,'card_accountnumber'); ?>
	</div>
        <div class="row" id="two">
                <?php echo  Yii::t('base','Save for Future Recharge'); ?>
                <?php  
                     if($defaultpay==2){?>
                         <input type="checkbox" name="CardInfo[defaultpay]" id="CardInfo_defaultpayc" value="2" checked="true"/>
                     <?php }else{ ?>
                           <input type="checkbox" name="CardInfo[defaultpay]" id="CardInfo_defaultpayd" value="2" onclick="return chooseCheckbox();"/>
                     <?php  }  ?>
                
        </div>
        </div>
	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? Yii::t('base','Create') : Yii::t('base','Save')); ?>
	</div>

<?php $this->endWidget(); ?>

</div>
<!-- form -->
<script type="text/javascript">
function chooseCheckbox(){
    if($('#CardInfo_defaultpayd').is(':checked')){
         $('#CardInfo_defaultpaya').attr('checked',false);
  }
  else if($('#CardInfo_defaultpayb').is(':checked')){
        $('#CardInfo_defaultpayc').attr('checked',false);
  }
}
</script>